//定义一个正则
$(function () {
    let form = layui.form;
    form.verify({
        pwd:[
            /^[\S]{6,15}$/,
            '密码必须是6-15位的非空字符'
        ],
        newPwd:function (value) {
            let v1 = $('[name=oldPwd]').val();
            if(v1 == value){
                return '新旧密码不能相同!'
            }
        },
        rePwd:function (value) {
            let v2 = $('[name=newPwd]').val();
            if(v2 !== value){
                return '两次新密码不一致!'
            }
        }
    })

    //点击事件修改密码
    $('#formPwd').on('submit', function (e) {
        e.preventDefault();
        axios({
            method:'POST',
            url:'/my/updatepwd',
            data:$(this).serialize(),
        }).then(function (res) {
            // console.log(res.data)
            if(res.data.status !== 0){
                return layui.layer.msg(res.data.message);
            };
             layui.layer.msg('恭喜您,修改密码成功');
             //重置表单
             $('form')[0] .reset()
            //跳转到登录页面
            window.parent.location.href = '../login.html'
        })
    })



})